package com.pattern.strategy.comparator;

public class MySorter<T> {

    /**
     * 注意： 该方法中两个都指定泛型
     * @param arr
     * @param comparator
     */
    public void sort(T[] arr, MyComparator<T> comparator) {
        for (int i = 0; i < arr.length; i++) {
            int minPos = i;
            for (int j = i+1; j < arr.length; j++) {
                minPos = comparator.compare(arr[j], arr[minPos]) == -1 ? j : minPos;
            }

            swap(arr, i, minPos);
        }
    }

    void swap(T[] arr, int i, int j){
        T temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

}
